package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.BpostionDO;
import com.bootdo.system.service.BpostionService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-03-18 19:36:43
 */
 
@Controller
@RequestMapping("/system/bpostion")
public class BpostionController {
	@Autowired
	private BpostionService bpostionService;
	
	@GetMapping()
	@RequiresPermissions("system:bpostion:bpostion")
	String Bpostion(){
	    return "system/bpostion/bpostion";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:bpostion:bpostion")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<BpostionDO> bpostionList = bpostionService.list(query);
		int total = bpostionService.count(query);
		PageUtils pageUtils = new PageUtils(bpostionList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:bpostion:add")
	String add(){
	    return "system/bpostion/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:bpostion:edit")
	String edit(@PathVariable("id") Long id,Model model){
		BpostionDO bpostion = bpostionService.get(id);
		model.addAttribute("bpostion", bpostion);
	    return "system/bpostion/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:bpostion:add")
	public R save( BpostionDO bpostion){
		if(bpostionService.save(bpostion)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:bpostion:edit")
	public R update( BpostionDO bpostion){
		bpostionService.update(bpostion);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:bpostion:remove")
	public R remove( Long id){
		if(bpostionService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:bpostion:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		bpostionService.batchRemove(ids);
		return R.ok();
	}

	/**
	 * 审核功能
	 */
	@ResponseBody
	@PostMapping("/audit")
	@RequiresPermissions("system:bpostion:audit")
	public R updateStatus(Long id ,Integer recomondStatus){

		if(bpostionService.updateStatusById(id,recomondStatus)){
//			try {
//				String send = WeRedPackUtils.send(UUID.randomUUID().toString(), scene_id, IPUtils.getIpAddr(httpServletRequest),
//						total_amount,
//						total_num,
//						wishing,
//						act_name,
//						remark,
//						bpostion.getOpenApi(),
//						partner,
//						wxappid,
//						sendName,
//						paternerKey,
//						certPath);
//
//			}catch (Exception e){
//				e.printStackTrace();
//			}

			return R.ok();
		}
		return R.error();
	}



}
